#ifndef CANDRIVER_H_
#define CANDRIVER_H_

#include "System\F2806x_Device.h"

class CANDriver
{	
private:
	// counters
	Uint32 m_Sent;
	Uint32 m_SendAborts;
	Uint32 m_ReadEmpty; // read issued, but no new data
	Uint32 m_ReadReceived; // valid new frame on read
		
public:
	bool Init();
	void SetupMBOX(Uint32 mboxIndex, Uint32 ID, int size, bool isTX);
	
	// transmit functions
	bool SendMBOX(Uint32 mboxIndex, float data, bool waitAck = false);
	bool SendMBOX(Uint32 mboxIndex, float data, Uint32 dataI, bool waitAck = false);
	bool SendMBOX(Uint32 mboxIndex, float64 data, bool waitAck = false);
	bool SendMBOX(Uint32 mboxIndex, Uint32 mdl, Uint32 mdh, bool waitAck = false);

	// receive functions
	bool ReadCANMBOX(Uint32 mboxIndex, float* ptr);
	bool ReadCANMBOX(Uint32 mboxIndex, bool* ptr);
	
private:
	void ResetCounters();
	bool ReadMBOX(Uint32 mboxIndex, int16* data);
	
};

extern void CANSetupBoxes(CANDriver* ptr);

#endif /*CANDRIVER_H_*/
